package com.icinfo.cloud.provider.punish.ucase.closearchiving.controller;

import com.icinfo.cloud.provider.punish.ucase.casemain.dto.CaseDetailInfoQueryDto;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseMainDetailInfoService;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseMainInfoService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CaseMainInfoVo;
import com.icinfo.cloud.provider.punish.ucase.closearchiving.dto.CaseCloseArchivingDto;
import com.icinfo.cloud.provider.punish.ucase.closearchiving.vo.CaseCloseArchivingEchoVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 *
 * 结案归档 controller
 * @author Administrator
 */
@RestController
@RequestMapping("/close")
@Slf4j
public class CloseArchivingController extends BaseController {

    @Resource
    private ICaseMainDetailInfoService caseMainDetailInfoService;

    @Resource
    private ICaseMainInfoService caseMainInfoService;



    /**
     *
     * ====================================================================结案归档=========================================================================
     *
     */

    /**
     * 结案归档
     * 是否需要审批
     * @param
     * @return
     */
    @PostMapping("/closeArchiving")
    public Result closeArchiving(@Validated @RequestBody CaseCloseArchivingDto caseCloseArchivingDto){
        // 存入宽表
        // 存入文书表
        // 存在附件表
        if (caseMainDetailInfoService.saveCloseInfo(caseCloseArchivingDto).size() == 1){
            return Result.success("success");
        }
        return Result.error("fail");
    }

    /**
     * 结案归档 回显
     *
     * @param
     * @return
     */
    @PostMapping("/closeArchivingEcho")
    public Result<CaseCloseArchivingEchoVo> closeArchivingEcho(@RequestBody CaseCloseArchivingDto caseDetailInfoQueryDto){
        return Result.success("success",caseMainDetailInfoService.closeArchivingEcho(caseDetailInfoQueryDto.getCaseId(),caseDetailInfoQueryDto.getDocumentCatalogCode()));
    }

    /**
     *  获取文号
     *
     * @param
     * @return
     */
    @PostMapping("/getCaseNumber")
    public Result<String> getCaseNumber(@Validated @RequestBody CaseDetailInfoQueryDto caseDetailInfoQueryDto){
        CaseMainInfoVo caseMainInfoVo = caseMainInfoService.getCaseMainInfo(caseDetailInfoQueryDto.getCaseId());
        if (caseMainInfoVo != null){
            return Result.success("success",caseMainInfoVo.getCaseNumber());
        }
        return Result.error("fail");
    }


}
